import {
  checkLogin
} from './auth.js'
new Vue({
  el: '#app',
  data: {
    IS_LOGIN: null,
    searchKey: '', // 搜索的关键词
    orderId: null,
    totalPrice: 0
  },
  async created() {
    this.IS_LOGIN = await checkLogin()
  },
  mounted() {
   // 获取请求的参数
   location.search.substring(1).split('&').forEach(item => {
     item = item.split('=')
     if (item[0] === 'out_trade_no') {
       this.orderId = item[1]
     }
     if (item[0] === 'total_amount') {
       this.totalPrice = item[1]
     }
   })
  },
  methods: {
    // 查找商品
    searchProduct() {
      console.log('查找商品:');
      location.href = `../web/search.html?searchKey=${this.searchKey}`
    },
    // 退出登录
    logout() {
      localStorage.removeItem('token')
      this.IS_LOGIN = null
      this.$message.success('退出成功')
    },
  }
})